package com.gobygang.client;

import com.gobygang.client.dialog.ProcessingDialog;
import com.gobygang.client.map.MapView;
import com.gobygang.client.uibinder.GobygangRoute;
import com.gobygang.client.uibinder.TaxiGangHome;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

public class GobygangRouteLoader implements Command{

	private TaxiGangHome taxiGangHome;

	public void setTaxiGangHome(TaxiGangHome taxiGangHome){
		this.taxiGangHome = taxiGangHome;
	}
	@Override
	public void execute() {
		GWT.runAsync(new RunAsyncCallback() {
			public void onFailure(Throwable caught) {
				Window.alert("Code download failed");
			}

			public void onSuccess() {
				GobygangRoute gobygangRoute = new GobygangRoute();
				if (taxiGangHome != null){
					RootPanel.get().remove(taxiGangHome);
				}

				RootPanel.get().add(gobygangRoute);
				GobygangProcessor.authenticate();

				gobygangRoute.showMenu();
				initPresenter(gobygangRoute);
				Gobygang.hideLoading();
				
				//for geolocation
				ProcessingDialog.show(Text.t.processing());

			}
		});

	}



	private void initPresenter(MapView mapView){
		GobygangPresenter taxiGangPresenter = GobygangPresenter.getInstance();
		taxiGangPresenter.setMapView(mapView);

	}
}
